<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>东莞新华投票系统v1.0</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <link rel="stylesheet" type="text/css" href="css/tipswindown.css" />
    <script src="js/jquery-1.5.2.js" type="text/javascript"></script>
    <script src="js/tipswindown.js" type="text/javascript"></script>
    <script src="js/ajaxfileupload.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(function () {
            var vsid    = $("#vsid").val();
            var options = $("#options").val();
            var account = $("#account").val();
            $("#submit").click(function(){
                var $check_boxes=$("input[name='vote_me']:checked");
                if($check_boxes.length<=0){ alert("请选择你支持的那个他/她!");return;}
                if(confirm("确定要提交吗？")){
                    var viids = new Array();
                    $check_boxes.each(function(){
                        viids.push($(this).val());
                    });
                    var str_viids = viids.join(',');
                    $.post('update-count.php',{"viids":str_viids,"account":account,"vsid":vsid},function(msg){
                        switch(msg)
                        {
                            case '1':
                                alert("投票成功！感谢您的参与和支持！");
                                window.location.href='index.php';
                                break;
                            case '2':
                                alert("亲！不能重复投票哦！");
                                window.location.href='index.php';
                                break;
                            default:
                                alert(msg);
                        }
                    });
                }
                    return false;
            });

            $("#reset").click(function(){
                $("input[name='vote_me']").each(function(){ $(this).removeAttr("checked")});
            });

            function checks_b(max){
                var cks = $(".vote_me_b");
                function check(){
                    var t=0;
                    for(i=0;i<cks.length;i++){
                        if(cks[i].checked){t++;}
                        if(t>max){return false;}
                     }
                    return true;
                }
                for(i=0;i<cks.length;i++){
                    cks[i].onclick=function(){
                        if(!check()){
                            alert("最多选择"+max+"个选项");
                            return false;
                        }
                    }
                }
            }

            function checks_f(max){
                var cks = $(".vote_me_f");
                function check(){
                    var t=0;
                    for(i=0;i<cks.length;i++){
                        if(cks[i].checked){t++;}
                        if(t>max){return false;}
                    }
                    return true;
                }
                for(i=0;i<cks.length;i++){
                    cks[i].onclick=function(){
                        if(!check()){
                            alert("最多选择"+max+"个选项");
                            return false;
                        }
                    }
                }
            }

            checks_b(1);
            checks_f(2);
        });
    </script>
</head>
<body id="dovote">

<?php
if (!isset($_COOKIE['islogin']) || $_COOKIE['islogin'] != 1) {
    echo "<script>window.location.href='login.php';</script>";
}

function checkVote($vsID,$account){
    $select_query_state = "select state from vote_subject where vsID=$vsID";
    $select_query_account="select uvID from user_vs where vsID=$vsID and account='$account'";

    $result_select_state = mysql_query($select_query_state) or die(mysql_error());
    $result_select_account = mysql_query($select_query_account) or die(mysql_error());
    $row_state = mysql_fetch_row($result_select_state);
    $row_account = mysql_fetch_row($result_select_account);
    if($row_state[0]=='进行中'){
        if($row_account){
            echo "<script>alert('亲，请勿重复投票');window.location.href='login.php';</script>";
        }
    }else{
        echo "<script>alert('亲，你来晚了，投票已截止。');window.location.href='login.php';</script>";

    }

}
require('config.php');
$vsID = $_GET['action'];
//$vsID = 36;
checkVote($vsID,$_COOKIE['username']);//检查该投票是否已经结束或者用户是否已经投票，主要防止用户直接复制粘贴投票页面网址进行投票。
$select_query_vs = "select description,options from vote_subject where vsID='$vsID'";
$select_query_vi_b = "select image,title,viID,viDES from vote_item where vsID='$vsID' and class='后援'";
$select_query_vi_f = "select image,title,viID,viDES from vote_item where vsID='$vsID' and class='前线'";

$result_query_vs = mysql_query($select_query_vs) or die(mysql_error());
$result_query_vi_b = mysql_query($select_query_vi_b) or die(mysql_error());
$result_query_vi_f = mysql_query($select_query_vi_f) or die(mysql_error());

$row_vs = mysql_fetch_array($result_query_vs);
$description = $row_vs[0];
$options = $row_vs[1];
$account = $_COOKIE['username'];
?>
<div id="nav">
    <div id="nav_top">
        <div class="width navs">
            <div class="logo">
                <a href="index.php"><img src="images/logo.png" width="290" height="54"/></a>
            </div>
            <div class="clear"></div>
        </div>
    </div>
    <div id="header">
        <div class="width">
            <p><strong>投票说明及规则：</strong></p>
            <input id="options" type="hidden" value="<?php echo $options ?>"/>
            <input id="account" type="hidden" value="<?php echo $account ?>"/>
            <input id="vsid" type="hidden" value="<?php echo $vsID ?>" />
            <p>
                <?php echo $description; ?>
            </p>
        </div>
    </div>
</div>

<div id="content">
    <div id="main-content">
       <div style="overflow: hidden;">
           <h3>月度明星评选--后援伙伴</h3>
        <?php
            while($row_vi=mysql_fetch_array($result_query_vi_b)){
                $path = "files/".$row_vi['image'];
        ?>
        <div class="vote_box">
            <img src="<?php echo $path; ?>" alt="选项图片"/>
            <p><?php echo $row_vi['title'];?></p>
            <div class="follow">
                <p><input type="checkbox" name="vote_me" value="<?php echo $row_vi['viID'];?>" class="vote_me_b"/>
                    选我----><a class="show_me" target="_blank" href="show-des.php?action=<?php echo $row_vi['viID'];?>">详情</a></p>
            </div>
        </div>
        <?php } ?>
        </div>

        <div style="overflow:hidden;">
            <h3>月度明星评选--前线伙伴</h3>
            <?php
            while($row_vi=mysql_fetch_array($result_query_vi_f)){
                $path = "files/".$row_vi['image'];
                ?>
                <div class="vote_box">
                    <img src="<?php echo $path; ?>" alt="选项图片"/>
                    <p><?php echo $row_vi['title'];?></p>
                    <div class="follow">
                        <p><input type="checkbox" name="vote_me" value="<?php echo $row_vi['viID'];?>" class="vote_me_f"/>
                            选我----><a class="show_me" target="_blank" href="show-des.php?action=<?php echo $row_vi['viID'];?>">详情</a></p>
                    </div>
                </div>
            <?php } ?>
        </div>
        <div id="btns"><button id="submit" style="width: 100px" class="btn btn-success">提交</button><button id="reset" style="width: 100px" class="btn btn-danger">重置</button></div>
    </div>

</div>

<!--footer be-->
<div id="footer" class="clear">
    <div
        style="background: url(images/gx_footer.gif) no-repeat; width: auto; height: 118px; padding: 20px 0 0 0;">
        <div class="width">
            <div style="text-align: center; font-size: 14px;">
                <a href="http://10.44.152.49">东莞新华导航页</a> <a
                    href="http://10.44.152.252./purchase" class="a1" target="ifm">采购立项签报系统</a> <a
                    href="http://10.44.152.166:8080/che/">用车管理系统</a> <a href="http://10.44.152.166:8080/caigou/"
                    >采购随机筛选系统</a>
            </div>
            <div style="margin: 15px 0 0 0; font-size: 11px; text-align: center;">新华人寿保险股份有限公司东莞中心支公司
                版权所有 东莞新华办公室
            </div>
        </div>
    </div>
</div>
</body>
</html>